<template>
  <div class="paySuccess" style="padding-bottom: 100px; margin-top: 100px">
    <div class="payBox">
      <div class="payTitle">
        <h2>XPay收银台 收款方:Exrick</h2>
      </div>
    </div>
    <div class="payContainer">
      <a href="javascript:;" class="titleSuccess" @click="pay">立即支付</a>
      <p class="payMoney">{{ orderId.totalPrice}}</p>
      <div class="imgBox">
        <img src="./images/feng.jpg" style="width: 200px; height: 160px" />

        <div class="imgText">
          <img src="./images/T1bdtfXfdiXXXXXXXX.png" />
          <div class="imgTextr">
            打开手机支付宝
            <br />
            点一下继续支付
          </div>
        </div>
      </div>
      <a class="toDetail" href="https://mobile.alipay.com/index.htm"
        >首次使用请下载手机支付宝</a
      >
    </div>
    <div class="payBottom">
      <div>
        <em><span>￥</span>{{ orderId.totalPrice}}</em>
        <input
          data-v-612d7650=""
          data-v-2cac025d=""
          type="text"
          readonly="readonly"
          disabled="disabled"
          class="disabled-btn"
          value="请勿离开"
          data-v-26571f4f=""
          style="
            width: 120px;
            height: 40px;
            font-size: 16px;
            line-height: 38px;
            text-align: center;
          "
        />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "PayLoad",
  data() {
    return {
      orderId: {},
      payStatus: 0,
    };
  },
  beforeMount() {
    this.orderId = this.$route.query;
  },
  mounted() {
     console.log(this.orderId)
    this.geyPaySuccess();
  },
  methods: {
    geyPaySuccess() {
      this.$store.dispatch("getPayInfoList", this.orderId);
    },
    pay() {
      try {
        this.$alert(`<img src="/images/ewm.png">`, "请使用支付宝扫码支付", {
          dangerouslyUseHTMLString: true,
          showClose: false,
          showCancelButton: true,
          cancelButtonText: "支付遇到问题",
          confirmButtonText: "我已成功支付",
          center: true,
          // 关闭之前的回调
          beforeClose: (action, instance, done) => {
            if (action === "confirm") {
              if (!this.payStatus) {
                this.$message.warning("请确保支付成功，支付成功跳转到成功页面");
              }

              //  不用支付跳转
              //  关闭定时器
              //  clearInterval(this.timer)
              //  this.timer=null
              // //  关闭对话框
              // done()
              //跳到成功页面
              // this.$router.push('/paysuccess')
            } else if (action === "cancel") {
              this.$message.success("支付遇到问题请联系尚硅谷前台小姐姐");
              //关闭定时器
              clearInterval(this.timer);
              this.timer = null;
              // 关闭对话框
              done();
            }
          },
        })
         .then(() => {}) 
         .catch(() => {})
        // 轮询
        if (!this.timer) {
          this.timer = setInterval(async () => {
            try {
              const result = await this.$API.reqPaySuccess(this.orderId);
              if (result.code === 200) {
                this.payStatus = 200;
                //  清除定时器
                clearInterval(this.timer);
                this.timer = null;

                // 关闭提示框
                this.$msgbox.close();
                // 跳到支付成功页面
                this.$router.push("/paysuccess");
              }
            } catch (error) {
              this.$message.warning("查询信息失败");
            }
          }, 2000);
        }
      } catch (error) {
        this.$message.warning(error);
      }
    },
  },
  computed: {
    ...mapState({
      payInfo: (state) => state.payInfo.payInfo,
    }),
  },
};
</script>

<style lang="less" scoped>
.paySuccess {
  width: 1220px;

  margin: 0 auto;
}
.payBox {
  position: relative;
  margin-bottom: 30px;
  overflow: hidden;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #dcdcdc;
  border-color: rgba(0, 0, 0, 0.14);
  box-shadow: 0 3px 8px -6px rgb(0 0 0 / 10%);
}
.payTitle {
  padding-left: 30px;
  position: relative;
  z-index: 10;
  height: 60px;
  padding: 0 10px 0 24px;
  border-bottom: 1px solid #d4d4d4;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 1px 7px rgb(0 0 0 / 6%);
  background: #f3f3f3;
  background: linear-gradient(#fbfbfb, #ececec);
  line-height: 60px;
  font-size: 18px;
  color: #333;

  display: flex;
  justify-content: space-between;
  align-items: center;
}
.payTitle h2 {
  font-size: 18px;
  font-weight: 400;
  color: #626262;
  display: inline-block;
}
.payContainer {
  display: -ms-flexbox;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 20px;
  margin-bottom: 60px;
}
.payContainer .titleSuccess {
  text-align: center;
  line-height: 24px;
  font-size: 14px;
  color: #999;
}
.payContainer .payMoney {
  text-align: center;
  font-size: 30px;
  color: #d44d44;
  font-weight: 700;
}
.imgbox {
  position: relative;
  width: 180px;
  height: auto;
  min-height: 168px;
  margin: 0 auto;
  padding: 6px;
  border: 1px solid #d3d3d3;
  box-shadow: 1px 1px 1px #ccc;
}
.imgText {
  margin: 5px 0 12px;
}
.imgTextr {
  font-size: 14px;
  color: #4d4d4d;
  line-height: 18px;
  margin: -35px 0 0 50px;
}
.toDetail {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -5px;
  font-size: 12px;
  color: #a6a6a6;
  text-decoration: underline;
  width: 25%;
  margin: 0 auto;
}
.payBottom {
  line-height: 60px;
  background: #f9f9f9;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-sizing: border-box;
}
.payBottom > div {
  display: flex;
  border-radius: 5px;
  justify-content: flex-end;
  align-items: center;
  padding: 0 20px;
}
.disabled-btn {
  cursor: not-allowed;
  border: 1px solid #afafaf;
  border-radius: 4px;
  color: #fff;
  background-color: #a9a9a9;
  background-image: linear-gradient(180deg, #b8b8b8, #a9a9a9);
}
.payBottom em {
  margin-left: 5px;
  font-size: 24px;
  color: #d44d44;
  font-weight: 700;
  margin-right: 20px;
}
</style>
